/**
 *
 * User: zeng/7047729872@qq.com
 * Date: 2018/3/30
 * Time: 17:43
 */


/* 变量定义 */
var slideIndex = 1;
var slidesFun = null;
var prevEl = document.getElementsByClassName('prev')[0];
var nextEl = document.getElementsByClassName('next')[0];
var imgSlides = document.getElementsByClassName("banner_li");

var imgLengthFlag = false;

/* 方法执行 */
showSlides(slideIndex);

/* 切换图片 */
function showSlides(n) {
    if (n > imgSlides.length) {
        slideIndex = 1
    }
    if (n < 1) {
        slideIndex = imgSlides.length
    }
    for (let i = 0; i < imgSlides.length; i++) {
        imgSlides[i].style.display = "none";
    }
    imgSlides[slideIndex - 1].style.display = "block";
}
/* 如果背景图只有一张的话，不需要轮播 */
if (imgSlides.length <= 1) {
    var np = document.getElementsByClassName('np');
    for (var i = 0; i < np.length; i++) {
        np[i].style.display = 'none';
    }
    imgLengthFlag = true;
    auto();
}

/* 翻页 */
function plusSlides(n) {
    showSlides(slideIndex += n);
}

/* 自动播放 */
function auto() {
    slidesFun = setInterval(function () {
        showSlides(slideIndex += 1);
    }, 5000);

    prevEl.style.opacity = 0;
    nextEl.style.opacity = 0;
}

/* 清除播放 */
function clearAuto() {
    clearInterval(slidesFun);
    // debugger
    if (!imgLengthFlag) {
        prevEl.style.opacity = 0.8;
        nextEl.style.opacity = 0.8;
    }
}

/* 设置透明度 */
function setOpacityOne() {
    var htmlCollectionOf = document.getElementsByClassName('np');
    htmlCollectionOf[0].style.opacity = .8;
    htmlCollectionOf[1].style.opacity = .8;
}

function setRegionBlock(isBlock) {
    var byClassName = document.getElementsByClassName('region');
    isBlock ? byClassName[0].style.display = 'block' : byClassName[0].style.display = 'none';
}


/*选择区域动态赋值*/
function chooseRegion(obj) {
    $('.current_region').html($(obj).html());
    setRegionBlock(false);
    $('#countyId').val($(obj).attr("value"));
}

/*热词点击效果*/
function hotkeyword(obj){
    $('#keyword').val($(obj).text());
}
